package com.tansun.easycare.rule.ruleversion.entity;

import java.io.Serializable;
import java.sql.Clob;

import org.hibernate.validator.constraints.Length;

import com.tansun.easycare.rule.common.entity.RuleBaseEntity;
import com.tansun.easycare.rule.exception.BizException;
import com.tansun.easycare.rule.rulemange.entity.RuleManage;
import com.tansun.easycare.rule.utils.DBUtils;
import com.tansun.rule.utils.RFDate;

/**
 * 版本信息Entity
 *
 * @author lxs
 * @version 2017-02-28
 */
public class RuleVersioninfo extends RuleBaseEntity<RuleVersioninfo> implements Serializable{

    private static final long serialVersionUID = 1L;
    private String manageId;        // 规则管理ID
    private String projectCode;        // 规则库编码
    private String modelType;        // 规则模型类型
    private String version;        // 规则模型版本号
    private String ruleContent;        // 规则内容drl版本
    private String ruleContentJava;		// 规则内容java版本
    private String javaClassName;	// java代码类名
    private String javaPackages;	// java代码引用的jar包
    private String javaInnerClasses;	// java代码内部类名
    private String javaImportClasses;	// java代码引用的类名
    private String jarIds;				//数据库中对应的jar包ID
    private String globalCode; 			//全局java代码
    private String championChallengerInfo;   //冠军挑战者信息
    private String isValid;    //是否有效   0：无效，     1：有效

    private String enterPointer;//调用编码
    /**
     * 规则模型编号
     */
    private String modelCode;
    /**
     * 1代表是被引用
     */
    private String refModelStatus;
    
    private  String  datasetNames;
    
    public String getChampionChallengerInfo() {
		return championChallengerInfo;
	}

	public void setChampionChallengerInfo(String championChallengerInfo) {
		this.championChallengerInfo = championChallengerInfo;
	}
	/**
     * 规则模型名称
     */
    private String modelName;

    public RuleVersioninfo() {
        super();
    }

    public RuleVersioninfo(String id) {
        super(id);
    }
    
	public com.tansun.ruledata.entity.RuleVersioninfo changeClass(){
		com.tansun.ruledata.entity.RuleVersioninfo newinfo = new com.tansun.ruledata.entity.RuleVersioninfo();
		if(createDate!=null)newinfo.setCreateDate(RFDate.getDateString(createDate));
		newinfo.setEnterPointer(enterPointer);
		newinfo.setId(id);
		newinfo.setModelCode(modelCode);
		newinfo.setManageId(manageId);
		newinfo.setModelName(modelName);
		newinfo.setModelType(modelType);
		newinfo.setProjectCode(projectCode);
		newinfo.setRefModelStatus(refModelStatus);
		newinfo.setRuleContent(DBUtils.ClobToString(ruleContent));
		newinfo.setVersion(version);
		return newinfo;
	}

	public RuleVersioninfo copyBean() {
		RuleVersioninfo copy = new RuleVersioninfo();
		copy.setChampionChallengerInfo(championChallengerInfo);
		copy.setCreateBy(createBy);
		copy.setCreateDate(createDate);
		copy.setDelFlag(delFlag);
		copy.setEnterPointer(enterPointer);
		copy.setGlobalCode(globalCode);
		copy.setId(id);
		copy.setIsNewRecord(isNewRecord);
		copy.setIsValid(isValid);
		copy.setJarIds(jarIds);
		copy.setJavaClassName(javaClassName);
		copy.setJavaImportClasses(javaImportClasses);
		copy.setJavaInnerClasses(javaInnerClasses);
		copy.setJavaPackages(javaPackages);
		copy.setManageId(manageId);
		copy.setModelCode(modelCode);
		copy.setModelName(modelName);
		copy.setModelType(modelType);
		copy.setProjectCode(projectCode);
		copy.setRankRelationId(this.getRankRelationId());
		copy.setRankRelationIds(this.getRankRelationIds());
		copy.setRefModelStatus(refModelStatus);
		copy.setRemarks(remarks);
		copy.setRuleContent(ruleContent);
		copy.setRuleContentJava(ruleContentJava);
		copy.setUpdateBy(updateBy);
		copy.setUpdateDate(updateDate);
		copy.setVersion(version);
		return copy;
	}
	
    @Length(min = 1, max = 64, message = "规则管理ID长度必须介于 1 和 64 之间")
    public String getManageId() {
        return manageId;
    }

    public void setManageId(String manageId) {
        this.manageId = manageId;
    }

    @Length(min = 1, max = 50, message = "规则库编码长度必须介于 1 和 50 之间")
    public String getProjectCode() {
        return projectCode;
    }

    public void setProjectCode(String projectCode) {
        this.projectCode = projectCode;
    }

    @Length(min = 0, max = 50, message = "规则模型类型长度必须介于 0 和 50 之间")
    public String getModelType() {
        return modelType;
    }

    public void setModelType(String modelType) {
        this.modelType = modelType;
    }

    @Length(min = 0, max = 10, message = "规则模型版本号长度必须介于 0 和 10 之间")
    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

	public String getModelCode() {
        return modelCode;
    }

    public void setModelCode(String modelCode) {
        this.modelCode = modelCode;
    }


    


	public String getRuleContent() {
		return ruleContent;
	}

	public void setRuleContent(String ruleContent) {
		this.ruleContent = ruleContent;
	}

	public String getRuleContentJava() {
		return ruleContentJava;
	}

	public void setRuleContentJava(String ruleContentJava) {
		this.ruleContentJava = ruleContentJava;
	}

	public String getJavaClassName() {
		return javaClassName;
	}

	public void setJavaClassName(String javaClassName) {
		this.javaClassName = javaClassName;
	}

	public String getJavaPackages() {
		return javaPackages;
	}

	public void setJavaPackages(String javaPackages) {
		this.javaPackages = javaPackages;
	}

	public String getModelName() {
        return modelName;
    }

    public void setModelName(String modelName) {
        this.modelName = modelName;
    }

    public String getJavaInnerClasses() {
		return javaInnerClasses;
	}

	public void setJavaInnerClasses(String javaInnerClasses) {
		this.javaInnerClasses = javaInnerClasses;
	}

	public String getJavaImportClasses() {
		return javaImportClasses;
	}

	public void setJavaImportClasses(String javaImportClasses) {
		this.javaImportClasses = javaImportClasses;
	}

	public String getGlobalCode() {
		return globalCode;
	}

	public void setGlobalCode(String globalCode) {
		this.globalCode = globalCode;
	}

	public String getJarIds() {
		return jarIds;
	}

	public void setJarIds(String jarIds) {
		this.jarIds = jarIds;
	}
	

	public String getIsValid() {
		return isValid;
	}

	public void setIsValid(String isValid) {
		this.isValid = isValid;
	}

	public String getRefModelStatus() {
		return refModelStatus;
	}

	public void setRefModelStatus(String refModelStatus) {
		this.refModelStatus = refModelStatus;
	}

	public void init(RuleManage ruleManage, String ruleContent) throws BizException {
        this.setProjectCode(ruleManage.getProjectCode());
        this.setModelType(ruleManage.getModelType());
        this.setManageId(ruleManage.getId());
        this.setChampionChallengerInfo(championChallengerInfo);
        this.setVersion(ruleManage.getVersion());
        this.setRuleContent(ruleContent);
        this.setCreateBy(ruleManage.getUpdateBy());
    }

    public void init(RuleManage ruleManage, String ruleContent, String ruleContentJava, String globalCode,String javaClassName,String javaPackages,String javaInnerClasses,String javaImportClasses,String jarIds) throws BizException {
        this.setProjectCode(ruleManage.getProjectCode());
        this.setModelType(ruleManage.getModelType());
        this.setManageId(ruleManage.getId());
        this.setChampionChallengerInfo(championChallengerInfo);
        this.setVersion(ruleManage.getVersion());
        this.setRuleContent(ruleContent);
        this.setRuleContentJava(ruleContentJava);
        this.setJavaClassName(javaClassName);
        this.setJavaPackages(javaPackages);
        this.setJavaImportClasses(javaImportClasses);
        this.setGlobalCode(globalCode);
        this.setJavaInnerClasses(javaInnerClasses);
        this.setJarIds(jarIds);
    }
    
	public String getEnterPointer() {
		return enterPointer;
	}

	public void setEnterPointer(String enterPointer) {
		this.enterPointer = enterPointer;
	}
//	public String getSql() {
//		return "INSERT INTO rule_versioninfo(id,manage_id,project_code,model_type,version,rule_content,enter_pointer,create_date,data_version)values(?,?,?,?,?,?,?,?,?)";
//	}
//	public Object[] getArgs(String timeStamp) {
//		return new Object[] {this.id,this.manageId,this.projectCode,this.modelType,this.version,this.ruleContent,this.enterPointer,new Date(),timeStamp};
//	}

	public String getSql() {
		return "INSERT INTO rule_versioninfo(id,manage_id,project_code,model_type,model_code,refmodelstatus,version,rule_content,rule_content_java,rule_java_classname,rule_java_packages,rule_java_inner_classes,rule_java_import_classes,global_code,jarIds,enter_pointer,create_date,data_version) values ";
	}
	public String getArgs(String timeStamp) {
		return "('"+this.id+"','"
				+isEmpty(this.manageId)+"','"
				+isEmpty(this.projectCode)+"','"
				+isEmpty(this.modelType)+"','"
				+isEmpty(this.modelCode)+"','"
				+isEmpty(this.refModelStatus)+"','"
				+isEmpty(this.version)+"','"
				+isEmpty(this.getRuleContent())+"','"
				+isEmpty(this.ruleContentJava)+"','"
				+isEmpty(this.javaClassName)+"','"
				+isEmpty(this.javaPackages)+"','"
				+isEmpty(this.javaInnerClasses)+"','"
				+isEmpty(this.javaImportClasses)+"','"
				+isEmpty(this.globalCode)+"','"
				+isEmpty(this.jarIds)+"','"
				+isEmpty(this.enterPointer)+"',@currDate,'"
				+timeStamp+"')";
//		return new Object[] {this.id,this.manageId,this.projectCode,this.modelType,this.version,this.ruleContent,this.enterPointer,new Date(),timeStamp};
	}
	public String getArgs(String timeStamp,String currDate) {
		return "('"+this.id+"','"
				+isEmpty(this.manageId)+"','"
				+isEmpty(this.projectCode)+"','"
				+isEmpty(this.modelType)+"','"
				+isEmpty(this.modelCode)+"','"
				+isEmpty(this.refModelStatus)+"','"
				+isEmpty(this.version)+"','"
				+isEmpty(this.getRuleContent())+"','"
				+isEmpty(this.ruleContentJava)+"','"
				+isEmpty(this.javaClassName)+"','"
				+isEmpty(this.javaPackages)+"','"
				+isEmpty(this.javaInnerClasses)+"','"
				+isEmpty(this.javaImportClasses)+"','"
				+isEmpty(this.globalCode)+"','"
				+isEmpty(this.jarIds)+"','"
				+isEmpty(this.enterPointer)+"','"+currDate+"','"
				+timeStamp+"')";
//		return new Object[] {this.id,this.manageId,this.projectCode,this.modelType,this.version,this.ruleContent,this.enterPointer,new Date(),timeStamp};
	}

    @Override
    public String toString() {
        return "RuleVersioninfo{" +
                "manageId='" + manageId + '\'' +
                ", projectCode='" + projectCode + '\'' +
                ", modelType='" + modelType + '\'' +
                ", version='" + version + '\'' +
                ", ruleContent='" + ruleContent + '\'' +
                ", ruleContentJava='" + ruleContentJava + '\'' +
                ", javaClassName='" + javaClassName + '\'' +
                ", javaPackages='" + javaPackages + '\'' +
                ", javaInnerClasses='" + javaInnerClasses + '\'' +
                ", javaImportClasses='" + javaImportClasses + '\'' +
                ", jarIds='" + jarIds + '\'' +
                ", globalCode='" + globalCode + '\'' +
                ", championChallengerInfo='" + championChallengerInfo + '\'' +
                ", isValid='" + isValid + '\'' +
                ", enterPointer='" + enterPointer + '\'' +
                ", modelCode='" + modelCode + '\'' +
                ", modelName='" + modelName + '\'' +
                '}';
    }

	public String getDatasetNames() {
		return datasetNames;
	}

	public void setDatasetNames(String datasetNames) {
		this.datasetNames = datasetNames;
	}


    
    
}